//
//  BCProjectTagView.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/12/19.
//  Copyright © 2018 guoshikeji. All rights reserved.
//

#import "BCProjectTagView.h"

@interface BCProjectTagView ()

@property (nonatomic, copy) UIImage *originalImage;

/**
 *tagLabel
 */
@property (nonatomic, strong) QMUILabel *tagLabel;

@end

@implementation BCProjectTagView

- (UIImage *)originalImage {
    if (!_originalImage) {
        _originalImage = LOAD_IMAGE(@"home_opt_cell_rect");
    }
    return _originalImage;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setSubviews];
    }
    return self;
}
- (void)setSubviews {
    //设置背景图片
    UIImage *originalImage = self.originalImage;
    UIImage *handlImage = [[originalImage stretchableImageWithLeftCapWidth:originalImage.size.width/2 topCapHeight:originalImage.size.height/2] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    self.image = handlImage;
    //
    self.tagLabel = [QMUILabel new];
    self.tagLabel.font = [UIFont qmui_systemFontOfSize:12 weight:QMUIFontWeightLight italic:true];
    self.tagLabel.textColor = [UIColor whiteColor];
    self.tagLabel.contentEdgeInsets = UIEdgeInsetsMake(0, 7, 0, 7);
    [self addSubview:self.tagLabel];
    [self.tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self);
    }];
}

- (void)setAlertTag:(NSString *)alertTag {
    _alertTag = alertTag;
    if (alertTag.length) {
        self.tagLabel.text = alertTag;
        [self.tagLabel sizeToFit];
    }
    CGFloat width = MIN(ScreenWidth/2-20.0, CGRectGetWidth(self.tagLabel.frame));
    self.frame = CGRectMake(0, 0, width, self.originalImage.size.height);
}

@end
